package com.yg.controller;


import com.yg.config.FilePathConfig;
import com.yg.config.result.R;
import com.yg.entity.readAndWriteTemplates.TeacherResearchPapersPlus;
import com.yg.service.TeacherResearchPapersService;
import com.yg.service.TeachingPracticeBaseService;
import com.yg.utils.CloseStream;
import com.yg.utils.DownLoadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
/**
 * <p>
 * 对应sheet08，此表为教师发表校验论文表
 前端控制器
 * </p>
 *
 * @author YingGu
 * @since 2020-11-04
 */
@RestController
@RequestMapping("/teacherResearchPapers")
@CrossOrigin
public class TeacherResearchPapersController {
    @Autowired
    private TeacherResearchPapersService teacherResearchPapersService;
    @Autowired
    private FilePathConfig filePathConfig;

    /**
     * 读取excel写入数据库
     * clr
     *
     * @param file
     * @return
     */
    @PostMapping("/readExcel")
    public R readExcel(MultipartFile file) {
        //获取fileInputStream
        FileInputStream fileInputStream = null;
        R r = null;
        try {
            fileInputStream = (FileInputStream) file.getInputStream();
            r = teacherResearchPapersService.readExcel(fileInputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //关闭fileInputStream
            CloseStream.closeFileInputStream(fileInputStream);
        }
        return r;
    }
    /**
     * 导出excel
     * clr
     *
     * @return
     */
    @GetMapping("/writeExcel")
    public R writeExcel(HttpServletResponse response, TeacherResearchPapersPlus teacherResearchPapersPlus) throws IOException {
        R r = teacherResearchPapersService.writeExcel(teacherResearchPapersPlus,response);
        return r;
    }
    /**
     * 查询所有
     * clr
     *
     * @return
     */
    @GetMapping("/getTeacherResearchPapers")
    public R selectAllTeacherInfo(int current,int size) {
        R r = teacherResearchPapersService.selectAllResearchPapersInfo(current,size);
        return r;
    }
    /**
     *  条件查询
     * @return
     */
    @PostMapping("/selectTeacherResearchPapersByCondition")
    public R researchPapersConditionalQuery(@RequestBody(required = false) String teacherCondition,String current,String size){
//        System.out.println("--------------------------" + teacherCondition);
        String s = "{'teacherId':'23'}";
        R r = teacherResearchPapersService.researchPapersConditionalQuery(teacherCondition,current,size);
        return r;
    }
    /**
     * 根据id更新教师信息
     * @return
     */
    @PutMapping("/putTeacherResearchPapers")
    public R updateResearchPapersInfo(@RequestBody String researchPapersJson){
        System.out.println(researchPapersJson);
        R r = teacherResearchPapersService.updateResearchPapersInfo(researchPapersJson);
        return r;
    }

    /**
     * 根据id删除教师信息
     * @param id
     * @return
     */
    @DeleteMapping("/deleteTeacherResearchPapers")
    public R deleteResearchPapersById(@RequestBody String id){
        System.out.println("---------------------"+id);
        R r = teacherResearchPapersService.deleteResearchPapersById(id);
        return r;
    }

    /**
     * 增加操作
     */
    @PostMapping("/postTeacherResearchPapers")
    public R insertResearchPapers(@RequestBody String teacherResearchPapers){
        R r=teacherResearchPapersService.insertResearchPapers(teacherResearchPapers);
        return r;
    }


}

